using MicroMsg.Common.Event;
using MicroMsg.Plugin.FaceBook.Scene;
using MicroMsg.Protocol;
using MicroMsg.Resource.@string;
using MicroMsg.UI.UserContrl;
using MicroMsg.UI.Util;
using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
namespace MicroMsg.UI.Page
{
	public class FaceBookBind : BasePage
	{
		private string currentToken;
		private EventWatcher bindWatcher;
		internal Grid LayoutRoot;
		internal TextBlock PageTitle;
		internal Grid ContentPanel;
		internal Button startBindBtn;
		private bool _contentLoaded;
		public FaceBookBind()
		{
			this.InitializeComponent();
		}
		private void startBindBtn_Click(object sender, RoutedEventArgs e)
		{
			FaceBookLoginPage.ShowFaceBookLoginPage(this, new FaceBookLoginCallBack(this.FaceBookLoginCB), true);
		}
		public void FaceBookLoginCB(bool isSuccess, string strToken)
		{
			if (!isSuccess)
			{
				return;
			}
			this.showProgressCover("waiting..");
			NetSceneFaceBookAuth netSceneFaceBookAuth = new NetSceneFaceBookAuth();
			netSceneFaceBookAuth.doScene(1, strToken);
			this.currentToken = strToken;
		}
		public static void ShowBindPage(BasePage originPage, bool isRemoveMe = false)
		{
			originPage.GoToPage("/Source/Plugin/Facebook/UI/FaceBookBind.xaml", null, isRemoveMe);
		}
		protected override void OnPageIn(object[] object_0)
		{
			this.InitBind();
		}
		protected override void OnPageOut()
		{
			this.UnitBind();
		}
		private void InitBind()
		{
			if (this.bindWatcher != null)
			{
				return;
			}
			this.bindWatcher = new EventWatcher(this, null, new EventHandlerDelegate(this.onBindEvent));
			EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_FACEBOOK_EVENT, this.bindWatcher);
		}
		private void UnitBind()
		{
			if (this.bindWatcher == null)
			{
				return;
			}
			EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_FACEBOOK_EVENT, this.bindWatcher);
			this.bindWatcher = null;
		}
		private void onBindEvent(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			if (evtArgs == null)
			{
				return;
			}
			FBAuthRet fBAuthRet = evtArgs.mObject as FBAuthRet;
			if (fBAuthRet == null)
			{
				this.hideProgressCover();
				return;
			}
			if (fBAuthRet.opType == 2)
			{
				return;
			}
			if (fBAuthRet.mIsSuccess)
			{
				BindingSuccess.ShowBindingSuccessPage(this, this.currentToken);
				this.hideProgressCover();
				return;
			}
			if (fBAuthRet.mRetCode == RetConst.MM_ERR_HAVE_BIND_FACEBOOK)
			{
				this.hideProgressCover();
				MMMessageBox.Show(strings.FaceBookHasBind, true, "确定");
				return;
			}
			this.hideProgressCover();
			MMMessageBox.Show(strings.FaceBookBindRetry, true, "确定");
		}
		private void showProgressCover(string strCoverTitle)
		{
			ProcessingCover.getProgressBar(this.LayoutRoot, strCoverTitle, null, false, false, null);
		}
		private void hideProgressCover()
		{
			ProcessingCover.releaseProgressBar(this.LayoutRoot);
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/Plugin/Facebook/UI/FaceBookBind.xaml", 2));
			this.LayoutRoot = (Grid)base.FindName("LayoutRoot");
			this.PageTitle = (TextBlock)base.FindName("PageTitle");
			this.ContentPanel = (Grid)base.FindName("ContentPanel");
			this.startBindBtn = (Button)base.FindName("startBindBtn");
		}
	}
}
